﻿using DevExpress.Data;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DXApplicationTangche.UC.抖音出入库.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.抖音出入库.抖音UC
{
    public partial class XtraUserControl抖音发货对账 : DevExpress.XtraEditors.XtraUserControl
    {
        public XtraUserControl抖音发货对账()
        {
            InitializeComponent();
        }
        public XtraUserControl抖音发货对账(List<DouyinStockOutCheckDTO> douyinStockOutCheckDTOs)
        {
            InitializeComponent();
            this.gridControl抖音发货出库对账.DataSource = douyinStockOutCheckDTOs;
            this.gridView抖音发货出库对账.RefreshData();
            this.gridView抖音发货出库对账.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(SummaryItemType.Sum, 
                "douyinStockOutQuantity", null, "(抖音发货数量合计= {0}  )"), });
            this.gridView抖音发货出库对账.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(SummaryItemType.Sum, "inventoryStockOutQuantity", null, "(库存发货数量合计= {0}  )"), });
            this.gridView抖音发货出库对账.GroupSummary.AddRange(new GridSummaryItem[] { new GridGroupSummaryItem(SummaryItemType.Sum, "inventoryStockInQuantity", null, "(当日入库未发货数量合计= {0}  )"), });
        }

        private void gridView抖音发货出库对账_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            try
            {
                if (e.RowHandle >= 0)
                {
                    DouyinStockOutCheckDTO douyinStockOutCheckDTO = (DouyinStockOutCheckDTO)gridView抖音发货出库对账.GetRow(e.RowHandle);
                    int douyinStockOutQuantity = douyinStockOutCheckDTO.douyinStockOutQuantity;//抖音发货数量
                    int inventoryStockOutQuantity = Convert.ToInt32(douyinStockOutCheckDTO.inventoryStockOutQuantity);//库存发货数量
                    int stockDifference = douyinStockOutQuantity - inventoryStockOutQuantity;//差异数量
                    if (stockDifference!=0)
                    {
                        if (e.Column.Name.Equals("gridColumn抖音发货数量"))
                        {
                            e.Appearance.BackColor = Color.Yellow;
                            //e.Appearance.ForeColor = Color.White;
                        }
                        if (e.Column.Name.Equals("gridColumn库存发货数量"))
                        {
                            e.Appearance.BackColor = Color.Yellow;
                            //e.Appearance.ForeColor = Color.White;
                        }
                    }
                    if (douyinStockOutCheckDTO.inventoryStockInQuantity>0)
                    {
                        if (e.Column.Name.Equals("gridColumn当日入库未发货数量"))
                        {
                            e.Appearance.BackColor = Color.LightYellow;
                            //e.Appearance.ForeColor = Color.White;
                        }
                    }
                }
            }
            catch { }
        }

        private void 导出excelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出excel文件";
            fileDialog.Filter = "Excel文件(*.xls)|*.xls";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.gridControl抖音发货出库对账.ExportToXls(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}
